//日报列表
var pageCount = 1;
function classOnload(a){
    console.log(a);
// }

//用户列表
var Json = {
    "pageIndex":a,
    "pageSize":9
}
ajax.post(ajax.myUrl+"daily/dailyList",Json,function(result){
    console.log(result);
    response(result);
    var data = result.dataset.dailyList;
    var tbody = document.querySelector("tbody");
    tbody.innerHTML = "";
    for(var i=0;i<data.length;i++){
        var newtr = document.createElement("tr");
        newtr.innerHTML=`
        <td>${data[i].dailyUserName}</td>
        <td class="second">${data[i].dailyContent}</td>
        <td>${data[i].dailyDate}</td>
        `;
        tbody.appendChild(newtr);
        // localStorage.setItem("userId"+i,data[i].userId);
    }

})

}


//点击写日志，弹出模态框
//获取模态框
var addReporter = document.getElementsByClassName("addReporter")[0];
var addition = document.getElementsByClassName("addition")[0];
var write = addition.getElementsByClassName("write")[0];
write.onclick = function(){
    addReporter.style.display = "block";
}

//点击添加班级模态框中的确定或取消，模态框消失
var sure = document.getElementsByClassName("sure")[0];
sure.onclick = function(){
    addReporter.style.display = "none";
    var dailyname = document.getElementsByClassName("dailyname")[0];
    var dailytime = document.getElementsByClassName("dailytime")[0];
    var dailycontent = document.getElementsByClassName("dailycontent")[0];

    var Json2 = {
        dailyDate:dailytime.value,
        dailyContent:dailycontent.value,
        dailyUserName:dailyname.value
    }
    ajax.post(ajax.myUrl+"daily/dailyList",Json2,function(result){
        console.log(result);

    })

}
var cancel = document.getElementsByClassName("cancel")[0];
cancel.onclick = function(){
    addReporter.style.display = "none";
}

//点击搜索
var search = document.getElementsByClassName("search")[0];
var btn = search.getElementsByTagName("button")[0];
var inp = search.getElementsByTagName("input")[0];
console.log(btn,inp);
btn.onclick = function(){
    var Json3 = {
        pageIndex:1,
        pageSize:5,
        dailyUserName:inp.value
    }
    ajax.post(ajax.myUrl+"daily/dailyList",Json3,function(result){
        console.log(result);
        var data = result.dataset.dailyList;
        var tbody = document.querySelector("tbody");
        tbody.innerHTML = "";
        for(var i=0;i<data.length;i++){
            var newtr = document.createElement("tr");
            newtr.innerHTML=`
            <td>${data[i].dailyUserName}</td>
            <td class="second">${data[i].dailyContent}</td>
            <td>${data[i].dailyDate}</td>
            `;
            tbody.appendChild(newtr);
            // localStorage.setItem("userId"+i,data[i].userId);
        }
    })
}


//右上角时间
var dailyTime = document.getElementById("dailyTime");
var nowTime = new Date();
var year = nowTime.getFullYear();
var month = nowTime.getMonth()+1;
var day = nowTime.getDate();
var hour = nowTime.getHours();
var minutes = nowTime.getMinutes();
if(month<10){
    month="0"+month;
}
dailyTime.setAttribute("value",year+"-"+month+"-"+day);


//管理员没有发布日志功能
var userrole = localStorage.getItem("userrole");
var write = document.getElementsByClassName("write")[0];
if(userrole == "管理员"){
    write.style.display = "none";
}